/******************************************************************
  Filename:	    CATM.C
  Product:      CATM APPLICATION
  Version:      1.0
  Module:       CATM
  Description:	This is the sample implementaion of VMAC enabled App
				using the ACT2000 shared library
  
  Modification History:
    #		Date        Who				Comments
	1.0		DD-MMM-YYYY	VMAC Wizard		Initial Implementaion
*******************************************************************/
/******************************************************************
   Copyright (C) 2000-2001 by VeriFone Inc. All rights reserved.

 No part of this software may be used, stored, compiled, reproduced,
 modified, transcribed, translated, transmitted, or transferred, in
 any form or by any means  whether electronic, mechanical,  magnetic,
 optical, or otherwise, without the express prior written permission
                          of VeriFone, Inc.
*******************************************************************/

#include <stdlib.h>
#include <string.h>
#include <svc.h>
#include <svctxo.h>

//Include file for ACT2000
#include <applidl.h>
#include <acldev.h>
#include <aclstr.h>
#include <message.h>
#include <printer.h>


//Include file for EESL
//#include "C:\Verixaps\VMAC\include\logsys.h"
//#include "C:\Verixaps\VMAC\include\varrec.h"
//#include "C:\Verixaps\VMAC\include\eeslapi.h"
//#include "C:\VerixVaps\VMAC\ver150\include\logsys.h"
//#include "C:\VerixVaps\VMAC\ver150\include\varrec.h"
//#include "C:\VerixVaps\VMAC\ver150\include\eeslapi.h"
#include <logsys.h>
#include <varrec.h>
#include <eeslapi.h>

//Include file for Device Manager
//#include "C:\Verixaps\VMAC\include\devman.h"
//#include "C:\VerixVaps\VMAC\ver150\include\devman.h"
#include <devman.h>
#include <power.h>

//Application specific Include files
#include "UserIf.h"
#include "PobTran.h"
#include "CATM.h"
#include "Comm.h"
#include "Pinpad.h"
#include "Menu.h"
#include "uclcode.h"

// Global Variables for the Application
char	LogicalName[EESL_APP_LOGICAL_NAME_SIZE];	// To store the logical name of this Appl
short	hCon		= -1;	// Console	 handle
short	hPrinter	= -1;	// Printer	 handle
short	hMagReader	= -1;	// MagReader handle
int		hLAN		= -1;

unsigned char	ucEventData[250] ;	// CustomEvent Data Buffer.  INCREASE it for your requirement
#ifdef __arm
	unsigned short	usDataSize ;		// Size of the EventData Received
#endif
#ifdef  _TARG_68000
	unsigned int	usDataSize ;		// Size of the EventData Received
#endif
short			shInputEvent;		// Input Event which could not be processed
char			cSenderName[10];	// Logical Name of the Appl which sent the Event
int inIklan = 0;
extern char Iklan[1000];
unsigned long lnIdleTimer = 0L;
int inPvsUnlockKeyboard = 1;

int spipe;
int remoteTaskID;
int remotePipe;
extern long MenuItem;
extern TRANSACTION_OBJECT obTran;
extern PINPAD_OBJECT   obPinPad;

unsigned long lnModemTimer = 0L;
unsigned long lnBackLightTimer = 0L;
extern int inPvsModemLowPower;

short DoTekanKeyA(short sh);
short DoTekanKeyB(short sh);
short DoTekanKeyE(short sh);
short DoTekanKeyF(short sh);
short DoTekanKeyG(short sh);
short DoTekanKeyH(short sh);
short DoTekanCancel(short sh);
short DoTekanEnter(short sh);
short DoDisplayUnlockGuide(void);

void vdInitializeSyncDialTask();

void ExitApp()
{
#ifdef __arm
	unsigned short iEvent;
#else
	unsigned iEvent;
#endif
	short retVal;
	clrscr();
	DisplayStatus("Releasing Device...");
	close(hPrinter);
	close(hMagReader);
	close(hCon);
	//close(hLAN);
	inReleaseComm();
	close(obPinPad.inHandle);
	inCloseComPort();
	//SVC_WAIT(1000);
	hPrinter = -1;
	hMagReader = -1;
	hCon = -1;	// need to close the console only on an exit event
	hLAN = -1;
	obPinPad.inHandle = -1;
	iEvent = ACT_EVENT;

	LOG_PRINTFF((0x08L, "EESL_send_event...SENDING..."));
#ifdef __arm
	retVal = EESL_send_event("DEVMAN", RES_COMPLETE_EVENT, (unsigned char*)&iEvent,sizeof(short));
#else 
	retVal = EESL_send_event("DEVMAN", RES_COMPLETE_EVENT, (unsigned char*)&iEvent, sizeof(iEvent));				
#endif
	LOG_PRINTFF((0x08L, "EESL_send_event...RETVAL = %d", retVal));
	while(retVal) {
		SVC_WAIT(1000);
#ifdef __arm
		retVal = EESL_send_event("DEVMAN", RES_COMPLETE_EVENT, (unsigned char*)&iEvent,sizeof(short));
#else 
		retVal = EESL_send_event("DEVMAN", RES_COMPLETE_EVENT, (unsigned char*)&iEvent, sizeof(iEvent));
#endif
		LOG_PRINTFF((0x08L, "EESL_send_event...RETVAL = %d", retVal));
	}
	LOG_PRINTF(("EXIT : SENT RES_COMPLETE_EVENT to DEVMAN from %s",LogicalName));
}


// display the idle menu
void CheckDeviceAndShowIdle(int MenuAction)
{
	DisplayMenu(MenuAction);
	if (hCon == -1 || hMagReader == -1 || hPrinter == -1)
	{
		clrscr();
		write_at("CATM APPLICATION",strlen("CATM APPLICATION"),1,1);
		write_at("Device Not Ready!!",18,2,4);
		write_at("Device Not Ready!!",18,2,5);
		SVC_WAIT(2000);
		ExitApp();
	}
	else
	{
		//enable_hot_key();
		disable_hot_key();
	}	
}

//default handler defined for aie_main
short appl_coldboot ()	// Application specific initialization  
{
	return TRUE;		// successful initialization
}

//default handler defined for aie_main
short appl_idle_loop ()	// Application specific idle loop processing 750ms
{
	static unsigned int inReversal = 0;
	static int inAutoRevTimer = 0;
	disable_hot_key();
/*
	inIklan++;
	if (inIklan<20) {
		return BRANCH_EXIT;
	} else if (inIklan==20) {
		clrscrplus("* PROMOSI *");
	} else {
		if (DisplayIklan()==0) {
			inIklan = 0;
			ShowIdle(4);
		}
	}
*/
	if (inAutoRevTimer == 0) {
		inAutoRevTimer = inGetAutoReversalTimer();
	}
	inReversal++;
	if (inReversal%50==0) 
		LOG_PRINTFF((0x08L, "REVERSAL COUNT DOWN...%d",(75*inAutoRevTimer)-inReversal));

	if (inReversal%(75*inAutoRevTimer)==0) {  //every 10 menit
		clrscr();
		DisplayStatus("Check Reversal...");
		FindAndSendReversal();
		SVC_WAIT(500);
		//CheckDeviceAndShowIdle(4);	
		DisplayMenu(4);
		inReversal = 0;
	}
	vdFlushCardBuffer();       
	//vdFlushKeyboardBuffer();	//somehow iddle_loop stuck here? cause of this func
	return BRANCH_EXIT;
}
		
//default handler defined for aie_main
short slow_poll()   //250 ms
{
	static unsigned int i=0;
	i++;
	if (!(i%4)) {
		if (MenuItem>=1 && MenuItem<=4 && inIklan<20) {
			DisplayTopLogo();
		}
	}
	if (!(i%3)) {  //mechanism every 30s handled inside the function
		inDisplaySignalStrengthInterface();
	}
	if (!(i%3)) {  //mechanism every 30s handled inside the function
		inDisplayBatteryLevel();
	}
	if (!(i%4)) {
		if (get_dock_status() == HANDHELD_UNDOCKED) {
			if ((lnModemTimer > 0L) && (lnIdleTimer > lnModemTimer)) {
				if (inPvsModemLowPower == 0) {
					inPvsModemLowPower = 1;
				}
			}
			if ((lnBackLightTimer > 0L) && (lnIdleTimer > lnBackLightTimer)) {
				if (inPvsUnlockKeyboard == 1) {
					set_backlight(0);
					inPvsUnlockKeyboard = 0;
				} 
			} 
			lnIdleTimer += 1000;
			LOG_PRINTFF((0x08L, "IDLE TIMER = [%ld]", lnIdleTimer));
		} else {
			if (inPvsUnlockKeyboard == 0) {
				set_backlight(1);
				inPvsUnlockKeyboard = 1;
			}
			if (inPvsModemLowPower == 1) {
				inPvsModemLowPower = 0;
			}
		}
	}
	return BRANCH_EXIT;
}

//default handler defined for aie_main
short fast_poll()  //50 ms
{
	return BRANCH_EXIT;
}

short inCommonFunc(short state)
{
	LOG_PRINTFF((0x08L, "inCommandFunc"));
	disable_hot_key();
	lnIdleTimer = 0;
	return(BRANCH_EXIT);
}

short inExitFunc(short state)
{
	LOG_PRINTFF((0x08L, "inExitFunc"));
	//enable_hot_key();
	disable_hot_key();
	inIklan=0;
	lnIdleTimer = 0;
	return(BRANCH_EXIT);
}


//default handler defined for application table
short inEndTable(short state)
{
	return(BRANCH_EXIT);
}


//default handler defined for aie_main
short inActivateEvtResponder( )
{
}

//default handler defined for aie_main
short inDeactivateEvtResponder()
{
}


// function which gets called when DEVMAN sends an INIT_EVENT to the application
short InitHandler(short state)
{
//	hMagReader = open(DEV_CARD,0);
//	LOG_PRINTF(("Acquired MagCard Device in %s",LogicalName));
//	Magflag = 0; // magcard is obtained by the application init event
	return (BRANCH_EXIT);
}

// function which handles the ACT_EVENT from DevMan when a application selected from the FrontEnd Menu
short ActEventHandler(short state)
{
	int shCommLink=1;
	char szBuffer[128];

	hCon = open(DEV_CONSOLE, 0);
#ifdef __arm
	DisplayStatus("Initialisasi...");  //not work for O3750? will make ==> "Init Comm Error"
#else
	write_at("Initialisasi...", 15, 1, 8); 
#endif
	hMagReader = open(DEV_CARD,0);
	hPrinter = open(DEV_COM4,0);
	PrinterInit();
	inInitComPortForPinpad();

	//DisplayStatusFromFile(8);
	if (get_env(UCL_COMM, szBuffer, sizeof(szBuffer)-1)>0) {
		shCommLink = atoi(szBuffer);
	}
	do {
		LOG_PRINTFF((0x08L, "START INIT COMM..."));
		if ( inInitializeComm (shCommLink) == VS_SUCCESS ) break;
		DisplayStatus("Init Comm Error");
		vdScrollDisplay();
		DisplayStatus("Restarting...");
		SVC_WAIT(3000);
		//SVC_RESTART("F:CATM.OUT");
		SVC_RESTART("");
	} while (1);
	inColdInitPinpad(&obTran);
	//CreateBatchRecord();
	CheckDeviceAndShowIdle(0);
	LOG_PRINTF(("Activated the Application %s",LogicalName));
	memset(Iklan, 0x00, sizeof(Iklan));
	return (BRANCH_EXIT);
}

// function to read the card data after a card swipe happens
short ReadCardHandler(short state)
{
	inIklan=0;
	ProcessTrans(MenuItem=2);
	//inDoInfomasiSaldo(&obTran);
	//inEndComm();
	CheckDeviceAndShowIdle(4);
    //vdFlushCardBuffer();
	//vdFlushKeyboardBuffer();
	return (BRANCH_EXIT);
}

short DoCom1Event(short state)
{
	inIklan=0;
	//ProcessTrans(MenuItem=2);
	clrscrplus("PINPad Req Event");
	//inRunPINPadSession();
	inDoPinpadRecvProcessSend();
	//SVC_WAIT(5000);
	CheckDeviceAndShowIdle(4);
	return (BRANCH_EXIT);
}

short DoTekanKeyA(short sh)
{
	if (DoDisplayUnlockGuide()) return BRANCH_EXIT;
	if (inIklan>=20) {
		inIklan=0;
		DisplayMenu(4);
		return BRANCH_EXIT;
	}
	write_at("Move Menu...", 12, 1, 7);
	DisplayMenu(3);
	return BRANCH_EXIT;
}

short DoTekanKeyB(short sh)
{
	if (DoDisplayUnlockGuide()) return BRANCH_EXIT;
	if (inIklan>=20) {
		inIklan=0;
		DisplayMenu(4);
		return BRANCH_EXIT;
	}
	clrscr();
	inDisplaySignalStrengthInternalInterface();
	DisplayMenu(4);
	return BRANCH_EXIT;
}

short DoTekanKeyE(short sh)
{
	if (DoDisplayUnlockGuide()) return BRANCH_EXIT;
	if (inIklan>=20) {
		inIklan=0;
	} else {
		ProcessTrans(MenuItem=MenuItem);
	}
    //get_char();
	CheckDeviceAndShowIdle(4);
	return BRANCH_EXIT;
}

short DoTekanKeyF(short sh)
{
	if (DoDisplayUnlockGuide()) return BRANCH_EXIT;
	if (inIklan>=20) {
		inIklan=0;
	} else {
		ProcessTrans(MenuItem=MenuItem+1);
	}
	//get_char();
	CheckDeviceAndShowIdle(4);
	return BRANCH_EXIT;
}

short DoTekanKeyG(short sh)
{
	if (DoDisplayUnlockGuide()) return BRANCH_EXIT;
	if (inIklan>=20) {
		inIklan=0;
	} else {
		ProcessTrans(MenuItem=MenuItem+2);
	}
	//get_char();
	CheckDeviceAndShowIdle(4);
	return BRANCH_EXIT;
}

short DoTekanKeyH(short sh)
{
	if (DoDisplayUnlockGuide()) return BRANCH_EXIT;
	if (inIklan>=20) {
		inIklan=0;
	} else {
		ProcessTrans(MenuItem=MenuItem+3);
	}
	//get_char();
	CheckDeviceAndShowIdle(4);
	return BRANCH_EXIT;
}

int inPvsExitByCancel(void)
{
#ifdef __arm
	short shTaskNum = 0;
#endif
#ifdef  _TARG_68000
	int shTaskNum = 0;
#endif
	int inRet = 0;
	static unsigned long ticks = 0L;
	unsigned long CurrTicks;

	inRet = EESL_get_number_of_tasks(&shTaskNum);  //VMAC already run 2 tasks + 1 softpays if any + 1 catm if any
	LOG_PRINTFF((0x08L, "NUMBER OF TASK (%d) = [%d]", inRet, (int)shTaskNum));

	if (inRet==0 && shTaskNum>3) {
		CurrTicks = read_ticks();
		LOG_PRINTFF((0x08L, "Time Taken Between 2 Cancel = [%ld]", CurrTicks-ticks));
		if (CurrTicks-ticks>350) {
			ticks = CurrTicks;
		} else {
			LOG_PRINTFF((0x08L, "EXIT DETECTED"));
			ExitApp();
		}
	}
	return (VS_SUCCESS);
}

short DoTekanCancel(short sh)
{
	if (DoDisplayUnlockGuide()) return BRANCH_EXIT;

	if (inIklan>=20){
		inIklan=0;
		CheckDeviceAndShowIdle(4); 
	} else {
		if (MenuItem>=1 && MenuItem<=4) {
			//ExitApp();  //comment it to disable the cancel key
			inPvsExitByCancel();
		}else {
			CheckDeviceAndShowIdle(2);
		}
	}
	return BRANCH_EXIT;
}

short DoTekanEnter(short sh)
{
	int inKey = 0;
	if (inPvsUnlockKeyboard==0) {
		clrscr();
		set_font("F:asc4x16.vft");
		display_at(1, 2, " Press  -ALPHA- ", CLR_EOL);
		display_at(1, 3, "   To Unlock    ", CLR_EOL);
		inPvsTimeOut(3000L);
		do {
			if (KBHIT()) {
				inKey = get_char();
				break;
			}
			if (inPvsTimeOut(0L)) break;
		} while (1);
		LOG_PRINTFF((0x08L, "KEY = [%d]", inKey));
		if (inKey == ALPHA_KEY) {
			inPvsUnlockKeyboard = 1;
			set_backlight(1);
			inPvsModemLowPower = 0;
		}
		DisplayMenu(4);
	}
	return BRANCH_EXIT;
}

short DoTekanKeyStar(short sh)
{
#ifdef __arm
	short shTaskNum = 0;
#endif
#ifdef  _TARG_68000
	int shTaskNum = 0;
#endif
	int inRet = 0;

	if (DoDisplayUnlockGuide()) return BRANCH_EXIT;
	inRet = EESL_get_number_of_tasks(&shTaskNum);  //VMAC already run 2 tasks + 1 softpays if any + 1 catm if any
	LOG_PRINTFF((0x08L, "NUMBER OF TASK (%d) = [%d]", inRet, (int)shTaskNum));
	if (inRet==0 && shTaskNum>3) {
		LOG_PRINTFF((0x08L, "EXIT DETECTED"));
		ExitApp();
	}else {
		//SVC_RESTART("");
	}
	return BRANCH_EXIT;
}

short DoDisplayUnlockGuide(void)
{
	if (inPvsUnlockKeyboard==0) {
		clrscr();
		set_font("F:asc4x16.vft");
		write_at(" Press  -ENTER- ", 16, 1, 2);
		write_at("and Then -ALPHA-", 16, 1, 3);
		pause(150);
		DisplayMenu(4);
		return 1;
	} 
	return 0;
}

// function to process error conditons when a request event to devman is not processed per requirement
short ResNotAvailableHandler(short state)
{
	short retVal;

	switch(shInputEvent){
		case ACT_EVENT :
			LOG_PRINTF(("Application %s failed the ACT_EVENT",LogicalName));
			//pause(500);
			break ;
		
		case INIT_EVENT :
			LOG_PRINTF(("Application %s failed the INIT_EVENT",LogicalName));		
			//pause(500);
			break ;

		// Application can extend this SWITCH if needed specifically
		default:  
			LOG_PRINTF(("Application %s failed the Event ID %d",LogicalName,shInputEvent));
			//pause(500);
			break;
	}
	return (BRANCH_EXIT);
}

// Generic Handler for any custom Pipe Messages
short PipeHandler(short sh)
{
	short shRetVal = 0 ;

	disable_hot_key();
	if(EESL_queue_count() == 0){  // Check if the application is having messages
		LOG_PRINTF(("PipeHandler : Check if the app is having messages"));
		return BRANCH_EXIT ;
	}

    LOG_PRINTF(("Reading PIPE event in CATM"));
	//pause(500);
	shRetVal = EESL_read_cust_evt(ucEventData,sizeof(ucEventData),&usDataSize,cSenderName);
	if(shRetVal == APP_RES_SET_UNAVAILABLE) {
		memcpy((void *)&shInputEvent,(void *)ucEventData,usDataSize) ;
		LOG_PRINTF(("The Input Event %d caused DEVMAN to send APP_RES_SET_UNAVAILABLE",shInputEvent));
	}
	LOG_PRINTF(("EESL_read_cust_evt: Received Event ID %d & EventData size is %d",shRetVal,usDataSize));
	//pause(500);

	return shRetVal ;	// This will appropriately call the Custom Event handler
}


// This function is provided for completeness as this never occurs under VMAC environment 
short DefaultActivateHandler(short state)
{
    LOG_PRINTF(("In Default ACTIVATE IN"));
	return (BRANCH_EXIT);
}


//This function is called by the application whenever an user presses the HOTKEY in the terminal
short DeactivateEventHandler(short state)
{
	ExitApp();
	return (BRANCH_EXIT);
}

/**************************************************************************/
/*                    Idle transaction Process table                      */
/**************************************************************************/
PF_TABLE appl_table[] =
{
    #define					FT_PIPE_EVENT					0
    PipeHandler,
	#define					FT_INIT_EVENT                   1
    InitHandler,
	#define					FT_ACT_EVENT					2
    ActEventHandler,
	#define					FT_READCARD_EVENT	            3
    ReadCardHandler,
	#define					FT_COM1_EVENT					4
	DoCom1Event,
	#define PF_TEKANKEYA	5
			DoTekanKeyA,		
	#define PF_TEKANKEYB	6
			DoTekanKeyB,
	#define PF_TEKANKEYE	7
			DoTekanKeyE,
	#define PF_TEKANKEYF	8
			DoTekanKeyF,
	#define PF_TEKANKEYG	9
			DoTekanKeyG,
	#define PF_TEKANKEYH	10
			DoTekanKeyH,
	#define PF_TEKANCANCEL  11
			DoTekanCancel,
	#define PF_TEKANENTER   12
			DoTekanEnter,
	#define PF_TEKANKEYSTAR 13
			DoTekanKeyStar,
	#define					FT_UNAVAILABLE_EVENT			14
	ResNotAvailableHandler,		
	#define					FT_ACT_IN						15
	DefaultActivateHandler,
	#define					FT_DEACT_IN						16
	DeactivateEventHandler,
	#define					FT_COMMON                       17
    inCommonFunc,
	#define					FT_EXIT	                        18
    inExitFunc,
	#define					FT_ENDTBL                       19
    inEndTable,
    (PF_TABLE) END_TABLE
};

/**************************************************************************/
/*                    Main Idle State Branch Table                        */
/*            (this table is required for every application)              */
/**************************************************************************/
BRANCH_TBL_ENTRY idle_table[] =
{
    { PIPE_IN,					FT_PIPE_EVENT ,				idle_table	},
	{ INIT_EVENT,				FT_INIT_EVENT ,				idle_table	},
	{ ACT_EVENT,				FT_ACT_EVENT ,				idle_table	},
	{ APPL_CARD,				FT_READCARD_EVENT ,			idle_table	},
	{ C1_IN,					FT_COM1_EVENT,				idle_table  },

	{KEY_a,			PF_TEKANKEYA,   idle_table},
	{KEY_b,			PF_TEKANKEYB,	idle_table},
	{KEY_e,			PF_TEKANKEYE,	idle_table},
	{KEY_f,			PF_TEKANKEYF,	idle_table},
	{KEY_g,			PF_TEKANKEYG,	idle_table},
	{KEY_h,			PF_TEKANKEYH,	idle_table},
	{KEY_CANCEL,	PF_TEKANCANCEL,	idle_table},
	{KEY_STR,		PF_TEKANKEYSTAR,idle_table},
	{KEY_CR,		PF_TEKANENTER,	idle_table},


	{ APP_RES_SET_UNAVAILABLE,	FT_UNAVAILABLE_EVENT ,		idle_table	},
	{ SLOW_POLL_IN,				0 ,							idle_table	},
	{ FAST_POLL_IN,				0 ,							idle_table	},
	{ ACTIVATE_IN,				FT_ACT_IN ,					idle_table	},
	{ DEACTIVATE_IN,			FT_DEACT_IN ,				idle_table	},
	{ COMMON_FUNC,				FT_COMMON,					idle_table  },
	{ EXIT_FUNC,				FT_EXIT,					idle_table  },
    { END_TABLE,				FT_ENDTBL ,					idle_table	}
};


void vdInitializeSyncDialTask()
{
	int inLocalTaskId = get_task_id();
	char arguments[100];
	int inOwnerTaskId = 0xFF;
	char szDevName[DEVICE_NAME_SIZE];
	
	remotePipe = 0;
	spipe = 0;

	spipe = open (CATM_PIPE_ID, 0);		// Open primary task PIPE
	pipe_init_msg (spipe, 3);			// Initalize PIP (O/S call)
	sprintf(arguments,"%d%c",inLocalTaskId,0);
	LOG_PRINTFF((0x08L, "Run F:DIALER3.OUT %s", arguments));
	remoteTaskID = run ("F:DIALER3.OUT",arguments);
	if (remoteTaskID == -1)
	{
        DisplayStatus("System Error");
	}
	SVC_WAIT(80);
	MEMCLR (szDevName, DEVICE_NAME_SIZE);
	strcpy (szDevName, DIALER3_PIPE_ID);
	remotePipe = get_owner (szDevName, &inOwnerTaskId);
	pipe_connect (spipe,remotePipe); // connect pri & sec pipes 
	LOG_PRINTFF((0x08L, "Remote Task ID (%d)", remoteTaskID));
	sprintf(arguments, "Remote Task ID (%d)", remoteTaskID);
	DisplayStatus(arguments);
	SVC_WAIT(200);
}

int main (int argc, char *argv[])
{
	long error;
	EESL_CONTROL_STR gEeslData; // global memory for EESL
	EESL_CONTROL_STR* pgEeslData; // global memory for EESL
	pgEeslData = &gEeslData;	
	
	strcpy(LogicalName, "CATM");
	LOG_INIT(LogicalName,LOGSYS_COMM,LOGSYS_PRINTF_FILTER|EESL_DEBUG_GLOBAL|EESL_DEBUG_SEND_SUCCESS|EESL_DEBUG_RECEIVE_SUCC);
	//pause(500);

	error = EESL_Initialise(argv, argc, LogicalName, &gEeslData);
    
	LOG_PRINTF(("EESL_Initialise Returned :%d",error));
	//pause(500);
	CreateBatchRecord();
	inInitConfig();
	inRecountMenu();
	if (error != 0){
		return error;
	} else { 
		msg_select_file("display.dat");
		if (inGetCommLink() != 1) vdInitializeSyncDialTask();
		aie_main(idle_table, appl_table, appl_idle_loop, fast_poll, slow_poll,
					inActivateEvtResponder, inDeactivateEvtResponder);
	}
	return 0;
}


